<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Класс для профайлинга скрипта
 * Расширяет соответствующий стандартный класс
 * 
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class CF_Profiler extends CI_Profiler {

   /**
    * Compile Errors
    *
    * @access   private
    * @return   string
    */   
   function _compile_errors() {
      $output  = "\n\n";
      $output .= '<fieldset style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
      $output .= "\n";
      $output .= '<legend style="color:#cd6e00;">&nbsp;&nbsp;'.$this->CI->lang->line('profiler_errors').'&nbsp;&nbsp;</legend>';
      $output .= "\n";
      
      $errors = $this->CI->errors->get_errors();
      if (0 == count($errors)) {
         $output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_errors')."</div>";
      } else {
         $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
         
         foreach ($errors as $key => $val) {
            $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>".$key."&nbsp;&nbsp; </td><td width='50%' style='color:#cd6e00;font-weight:normal;background-color:#ddd;'>";
            $output .= htmlspecialchars(stripslashes($val));
            $output .= "</td></tr>\n";
         }
         
         $output .= "</table>\n";
      }
      $output .= "</fieldset>";

      return $output;   
   }
   
   /**
    * Run the Profiler
    *
    * @access   private
    * @return   string
    */   
   function run() {      
      $output = '<br clear="all" />';
      $output .= "<div style='background-color:#fff;padding:10px;'>";
      
      $output .= $this->_compile_memory_usage();
      $output .= $this->_compile_benchmarks();   
      $output .= $this->_compile_uri_string();
      $output .= $this->_compile_errors();
      $output .= $this->_compile_get();
      $output .= $this->_compile_post();
      $output .= $this->_compile_queries();
      
      $output .= '</div>';
      
      return $output;
   }

}
